import React from 'react'
import axios from 'axios'
import {withRouter} from 'react-router-dom'
import {connect} from "../../smox/smox-react"
import {add} from '../../smox/reducer'


@withRouter
@connect(
  state => ({num: state}),
  {add}
)

class AuthRoute extends React.Component {

  componentDidMount() {

    // 是否登录
    axios.get('/user/info').then(res => {
      if (res.status === 200) {
        if (res.data.code === 1) {
          this.props.history.push('/login')
        }
      }
    })

  }

  render() {
    return (
      <div>
        <h2>现在有机枪{this.props.num}把</h2>
        <button onClick={this.props.add}>申请武器</button>
      </div>
    )
  }
}

export default AuthRoute